package com.api.workflow.web;

import weaver.common.util.string.StringUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.DetailTable;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @author wanghan
 * @version 1.0
 * @Description
 * @since 2025/2/27 12:29
 */
public class PRPigeonholeAction extends BaseBean implements Action{
    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            //获得流程id
            String workflowid = requestInfo.getWorkflowid();
            //获取表id
            String requestid = requestInfo.getRequestid();
            writeLog("PRPigeonholeAction-----start----------------------" + requestid);
            RecordSet rs = new RecordSet();
            rs.execute("select tablename from workflow_base a,workflow_bill b where a.formid=b.id and a.id=" + workflowid);
            rs.next();
            //获取主表名
            DetailTable[] detailTable = requestInfo.getDetailTableInfo().getDetailTable();
            //获取主表名
            String maintable = Util.null2String(rs.getString("tablename"));

            //根据表id和主表名查找主表的相关信息
            rs.executeQuery("select * from " + maintable + " where requestid=?", new Object[]{requestid});
            rs.next();
            String cgbs = Util.null2String(rs.getString("cgbs"));
                    if(!StringUtil.isNullOrEmpty(cgbs)){
                       String sql="update uf_cgsqd set dqzt=2 where id=?";
                        writeLog("sql-----------" + sql);
                        rs.executeUpdate(sql,cgbs);
                    }
            return Action.SUCCESS;

        }catch (Exception e){
            e.printStackTrace();
            requestInfo.getRequestManager().setMessagecontent("接口出错,请联系管理员!"+e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
